package com.wenwan.manage.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wenwan.manage.service.GoodsCollectionService;
import com.wenwan.manage.setting.DefaultValue;

import javax.annotation.Resource;

/**
 * 商品收藏
 * 
 * @author Admin
 *
 */
@Controller
@RequestMapping(value = "/goods/collection")
public class GoodsCollectionController {

	@Autowired
	private GoodsCollectionService goodsCollectionService;

	@ResponseBody
	@RequestMapping(value = "/create", method = { RequestMethod.POST })
	public Map<String, Object> create(@RequestParam(required = true) String goodsId,
			@RequestParam(required = true) String userId) {
		return goodsCollectionService.create(goodsId, userId);
	}

	@ResponseBody
	@RequestMapping(value = "/delete/by/goods/and/user", method = { RequestMethod.POST })
	public Map<String, Object> deleteByGoodsAndUser(@RequestParam(required = true) String goodsId,
			@RequestParam(required = true) String userId) {
		return goodsCollectionService.deleteByGoodsAndUser(goodsId, userId);
	}

	@ResponseBody
	@RequestMapping(value = "/select/by/user/id", method = { RequestMethod.GET })
	public Map<String, Object> selectByUserId(@RequestParam(required = true) String userId) {
		return goodsCollectionService.selectByUserId(userId);
	}

	@ResponseBody
	@RequestMapping(value = "/delete/by/id", method = { RequestMethod.POST })
	public Map<String, Object> deleteById(@RequestParam(required = true) String id) {
		return goodsCollectionService.deleteById(id);
	}

	@ResponseBody
	@RequestMapping(value = "/select/all", method = { RequestMethod.GET })
	public Map<String, Object> selectAll(
			@RequestParam(required = false, defaultValue = DefaultValue.CURRENT_PAGE) Integer currentPage,
			@RequestParam(required = false, defaultValue = DefaultValue.PAGE_SIZE) Integer pageSize) {
		return goodsCollectionService.selectAll(currentPage, pageSize);
	}

}
